package com.eureka_consumer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Created with IntelliJ IDEA.
 * User: lixiao
 * Created Date: 2020/7/20 9:39
 */
@RestController
@RequestMapping(value = "/client")
public class client {

    @Autowired
    public RestTemplate restTemplate;
    @Autowired
    public LoadBalancerClient client;

    @GetMapping(value = "/do")
    public String request(String name){
        name += "!";
        ServiceInstance instance = client.choose("eureka-productor");
        String url = "http://" + instance.getHost() + ":" + instance.getPort() + "prductior/date";
        return restTemplate.getForObject(url, String.class);
    }
}